<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CRM系统</title>
<style type="text/css">
a{
text-decoration: none;
}
</style>
<script src="js/global.js"></script>
<canvas id="christmasCanvas"
	style="top: 0px; left: 0px; z-index: 5000; position: fixed; pointer-events: none;"></canvas>
<script>
//即时通讯
	var userName='<%=session.getAttribute("name")%>';
var webscoket = new WebSocket("ws:localhost:8080/CRMS/onlineStu/" + userName);
webscoket.onopen = function() {
}
webscoket.onmessage = function(event) {
	alert("提示消息：" + event.data);
}    
 function snow() {
			var b = document.getElementById("christmasCanvas");
			var a = b.getContext("2d");//getContext() 方法返回一个用于在画布上绘图的环境。2d二维绘图
			var d = window.innerWidth;//获取屏幕的宽
			var c = window.innerHeight;
			b.width = d;
			b.height = c;
			for(var e = [], b = 0;b < 70;b++) {
				e.push({
					x:Math.random() * d, //random() 方法可返回介于 0 ~ 1 之间的一个随机数
					y:Math.random() * c, 
					r:Math.random() * 4 + 1,
					d:Math.random() * 70
				});
			}
			var h = 0;
			window.intervral4Christmas = setInterval(
			function() {
				a.clearRect(0, 0, d, c);
				a.fillStyle = "rgba(83,172,150,0.4)";
				a.shadowBlur = 5;
				a.shadowColor = "rgba(83,172,150,0.4)";
				a.beginPath();
				for(var b = 0;b < 70;b++) {
				 var f = e[b];
				 a.moveTo(f.x, f.y);
				 a.arc(f.x, f.y, f.r, 0, Math.PI * 2, !0)
				}
				a.fill();
				h += 0.01;
				for(b = 0;b < 70;b++) {
					if(f = e[b], f.y += Math.cos(h + f.d) + 1 + f.r / 2, f.x += Math.sin(h) * 2, f.x > d + 5 || f.x < -5 || f.y > c) {
						e[b] = b % 3 > 0 ? {x:Math.random() * d, 
						y:-10, 
						r:f.r, d:f.d} : Math.sin(h) > 0 ? {x:-5, y:Math.random() * c, 
						r:f.r, d:f.d} : {x:d + 5, y:Math.random() * c, 
						r:f.r, d:f.d}
					};
				};
			}, 70);
		}; 
		 
	$(function() {
	    snow();
		$("#tt")
				.tree(
						{
							url : "index/tree",
							method : "POST",
							animate : true,
							lines : true,
							onClick : function(node) {
								var isLeaf = $('#tt').tree('isLeaf', node.text);
								if (isLeaf) {
									var flag = $('#tta').tabs('exists',
											node.text);
									if (flag) {
										$('#tta').tabs('select', node.text);
									} else {
										var root = $('#tt').tree('getParent',
												node.target)
										if (root != null) {
											$('#tta')
													.tabs(
															'add',
															{
																title : node.text,
																closable: true,
																content : "<iframe src='"
																		+ node.path
																		+ ".jsp' style='width:100%;height:600px;'/>"
															});
										}
									}
								}

							}
						});

		$("#UsersAll").combobox({
			url : 'syss/selectAlluserByisNotName',
			method : 'post',
			valueField : 'loginName',//填充进 <option value='id'>text</option>
			textField : 'loginName'//标签中间（<option>text</option>） 
		})

	})
	

	function fixHeight(percent) {
		return (document.body.clientHeight) * percent;
	}

	function fixWidth(percent) {
		return (document.body.clientWidth - 5) * percent;
	}

	function exit() {
		$('#mm').menu('show', {
			left : fixWidth(0.43),
			top : fixHeight(0.09)
		});
	}
	function person() {

		$("#dd").dialog("open");
	}
	//修改邮箱电话（用户信息）
	function save() {
		$.messager.confirm("确认信息", "确定修改？", function(r) {
			if (r) {
				$.post("index/updateTelAndEmail", {
					protectEmail : $("#pkemail").val(),
					protectMTel : $("#pktel").val()
				}, function(res) {
					if (res > 0) {
						$.messager.alert("提示", "信息保存");
						$("#dd").dialog("close");
					} else {
						$.messager.alert("提示", "保存失败");
						$("#dd").dialog("close");
					}
				}, "json")
			}

		})

	}
	function clear() {
		$("#dd").dialog("close");
	}
	//退出系统
	function remove() {
		$.messager.confirm('提示', '您想要退出该系统吗？', function(r) {
			if (r) {
				$.post("logout", {}, function(res) {
					if (res > 0) {
						$.messager.alert("提示", "已安全退出");
						window.location.href = "login.jsp";
					}
				}, "json")
			}
		});
	}

	function editpsw() {
		$("#Psw").dialog("open");

	}
	//修改密码
	function savePsw() {
		var flag = $("#pswFrm").form("validate");
		if(flag){
			$.messager.confirm("信息提示", "确定修改密码？", function(r) {
				if (r) {
					$.post("index/updatePsw", {
						passWord :$("#newPsw").val()
					}, function(res) {
						if(res>0){
							$.messager.alert("提示","修改成功");
							$("#Psw").dialog("close");
							window.location.href = "login.jsp";
						}else{
							$.messager.alert("提示","修改失败");
						}
					}, "json")
				}
			})
			
		}else{
			$.messager.alert("提示","不允许提交空值");
		}
	}
	function clearPsw() {
		$("#Psw").dialog("close");
	}
	//初始化密码
	function initpsw() {
		$.messager.confirm("信息提示", "确定初始化密码？", function(r) {
			if (r) {
				$.post("index/updatePsw", {
					passWord : "ysd123"
				}, function(res) {
					if(res){
						$.messager.alert("提示","初始化成功");
						$("#Psw").dialog("close");
					}else{
						$.messager.alert("提示","修改失败");
					}
				}, "json")
			}
		})
	}
	//签到
	function pin() {
		var btn = document.getElementById("qd");
		if (btn.innerText == "已签到") {
			piny();
		} else {
			$.post("index/addUserCheck", {
				checkState : "已签到"
			}, function(res) {
				if (res > 0) {
					if (res == 1) {
						$.messager.alert("提示", "签到成功");
						//数据库拿出
						btn.innerHTML = "已签到";
					} else if (res == 3) {
						$.messager.alert("提示", "还未到上班时间哦！！！");
					}

				} else {
					if (res == 0) {
						$.messager.alert("提示", "签到异常");
					} else {
						$.messager.alert("提示", "上班迟到");
						btn.innerHTML = "已签到";
					}

				}
			}, "json")
		}
	}
	function piny() {
		$.messager.alert("提示","今日已签到");
	}
	//签出
	function pout() {
		var btn = document.getElementById("qc");
		if (btn.innerText == "已签出") {
			pouty();
		} else {
			$.post("index/updateUserCheck", {
				isCancel : "已签出"
			}, function(res) {
				if (res > 0) {
					if (res == 1) {
						btn.innerHTML = "已签出";
						$.messager.alert("提示", "签出成功");
					} else {
						$.messager.alert("提示", "还未到下班时间哦！！！");
					}

				} else {
					$.messager.confirm("提示", "今日还未签到，无法签出！！！", function(r) {
						if (r) {
							$.messager.confirm("提示", "是否签到", function(a) {
								if (a) {
									pin();
								}
							})

						}
					})
				}
			}, "json");
		}

	}
	function pouty(){
		$.messager.alert("提示","今日已签出");
	}
	//动态提示信息
	var uid = <%=session.getAttribute("uid") %>;
	$(function(){
		/* alert(uid) */
		$.post("message/selectMyMessages",{
			uid:uid,
		},
		function(res){
			if (res!="") {
				$("#messages").datagrid({
					url:'message/selectMyMessages',
					method:"post",
					singleSelect:true, 
					queryParams:{
						uid:uid
					}
				})
				$("#MessageDialog").dialog("open");
				
			}
		},"json")
		
	})
	function RemoveMessage(){
		
		//弹出后删除
		$.post("message/RomoveMessages",{
			uid:'<%=session.getAttribute("uid") %>'
		},
		function(res){
			$("#MessageDialog").dialog("close");
		},"json"
		)
	}
	//即时通信
	function openSend() {
		$('#openSend-window').window("open");
	}
	function send() {
		var msg = $("#msg").combobox("getValue");
		var UsersAll = $("#UsersAll").combobox("getValue");
		if (UsersAll == "----请选择-----") {
			alert("请选择联系人发送信息！")
		} else {
			message = userName + "," + UsersAll + "," + msg;
			webscoket.send(message);
			//接收到消息的回调方法  
			$.messager.alert("提示", "发送成功！");//提示
			$('#openSend-window').window("close");
		}
	}
	//修改密码
	function UpdatePassword() {
		$('#updateMMDialog').dialog("open");
	}
	function submitUpdateMM() {
		var passWord=$("#passWord").val();
		var newPW=$("#newPW").val();
		var querenPW=$("#querenPW").val();
			$.post(
			    	'index/updatePersionMM',
			    	{ 
			    		passWord:passWord,
			    		newPW:newPW,
			    		querenPW:querenPW
		 	},function(res){
		 	   if(res>0){
		 			$.messager.alert("提示","修改成功");//提示
		 			$("#updateMMDialog").dialog("close");//关闭弹窗
		 			window.location.href="login.jsp";
					}else if(res==-2){
						$.messager.alert("提示","新密码和确认密码不一致！");//提示
					}else{
						$.messager.alert("提示","修改失败！");//提示
					} 
		  },'json')
	}
	function closeUpdateMM() {
		$('#updateMMDialog').dialog("close");
	}
</script>
</head>
<body>

<%HttpSession s= request.getSession();%>
	<div id="Psw" class="easyui-dialog" title="个人空间"
		style="width: 240px; height: 300px;"
		data-options="modal:true,closed:true,buttons:[{
				text:'保存',
				iconCls:'icon-save',
				handler:function(){
				savePsw()
				}
			},{
				text:'取消',
				iconCls:'icon-clear',
				handler:function(){
				clearPsw()
				}
			}]">
		<form id="pswFrm">
			<table>

				<tr>
					<td colspan="2"><h2>个人密码修改</h2></td>

				</tr>
				<tr>
					<td>新密码:</td>
					<td><input type="password" id="newPsw"
						class="easyui-validatebox" data-options="required:true" /></td>
				</tr>
			</table>
		</form>

	</div>

	<div style="margin: 20px 0;"></div>
	<div id="dd" class="easyui-dialog" title="个人空间"
		style="width: 240px; height: 300px;"
		data-options="modal:true,closed:true,buttons:[{
				text:'保存',
				iconCls:'icon-save',
				handler:function(){
				save()
				}
			},{
				text:'取消',
				iconCls:'icon-clear',
				handler:function(){
				clear()
				}
			}]">
		<form id="psfrm">
			<table>
				<tr style="text-align: center;">
					<td colspan="2"><h3>个人信息</h3></td>
				</tr>
				<tr >
				<td>签到状态：</td>
					<td  style="font-size: 12px"><%if(s.getAttribute("qdstate")!=null){%>
					<a href="javascript:void(0)"
						onclick="piny()" id="qd">
						<%=s.getAttribute("qdstate") %>
						</a>
						<%}else{ %>
						<a href="javascript:void(0)"
						onclick="pin()" id="qd">
						未签到
						</a>
						<%} %>
						<%if(s.getAttribute("qcstate")!=null){%>
						&ensp;&ensp;<a href="javascript:void(0)"
						id="qc" onclick="pouty()">
						<%=s.getAttribute("qcstate") %>
						</a>
						<%}else{ %>
						&ensp;&ensp;<a href="javascript:void(0)"
						id="qc" onclick="pout()">未签出</a>
						<%} %>
						</td>
				</tr>
				<c:forEach items="${user}" var="u">
				
					<tr>
						<td>姓名：</td>
						<td>${u.loginName}</td>
					</tr>
					<tr>
						<td>职业：</td>
						<c:forEach items="${RolesName}" var="r">
							<td>${r.name}</td>
						</c:forEach>
					</tr>
					<tr>
						<td>电话：</td>
						<td><input type="text" class="easyui-textbox" id="pktel"
							value="${u.protectMTel}" /></td>
					</tr>
					<tr>
						<td>邮箱：</td>
						<td><input type="text" class="easyui-textbox" id="pkemail"
							value="${u.protectEmail}" /></td>
					</tr>
				</c:forEach>
				<tr>
					<td colspan="2">密码功能区块：</td>
				</tr>
				<tr>
					<td colspan="2"><hr></td>
				</tr>
				<tr>
					<td><a href="javascript:void(0)" onclick="editpsw()"
						class="easyui-linkbutton" data-options="iconCls:'icon-cut'">改</a></td>
						<td>
						<a href="javascript:void(0)" onclick="UpdatePassword()"
						class="easyui-linkbutton" data-options="iconCls:'icon-cut'">修改密碼</a></td>
					
				</tr>
				<tr>
				<td></td>
				<td><a href="javascript:void(0)" onclick="initpsw()"
						class="easyui-linkbutton" data-options="iconCls:'icon-reload'">初始密码</a></td>
				</tr>
			</table>
		</form>
	</div>
	<div class="easyui-layout" style="width: 100%; height: 700px;">
		<div data-options="region:'north'" style="height: 80px">
			<div style="text-align: center;">
				<h2 style="text-align: center;" id="t">
					欢迎<a href="javascript:void(0)" onclick="exit()">${name}</a>登陆CRM权限系统
					<br>系统当前时间是：<span></span>年<span></span>月<span></span>日<span></span><span></span>时<span></span>分<span></span>秒
				<a href="javascript:void(0)" style="float: right;"
						class="easyui-linkbutton" onclick="openSend()"
						data-options="iconCls:'icon-man'">通讯录</a>
						
				</h2>
				<script>
					        var ss=document.getElementById('t').getElementsByTagName('span');
					        function changetime(){
								var time=new Date();
								var days = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
					            ss[0].innerHTML=time.getFullYear();
					            ss[1].innerHTML=time.getMonth()+1;
					            ss[2].innerHTML=time.getDate();
					            ss[3].innerHTML=days[time.getDay()];
					            ss[4].innerHTML=time.getHours();
					            ss[5].innerHTML=time.getMinutes();
					            ss[6].innerHTML=time.getSeconds();
					        }
					        changetime();
					        setInterval(function(){
					            changetime();
					        },1000)
		    			</script>
				
				<div id="mm" class="easyui-menu" style="width: 120px;">
					<div onclick="person()" data-options="iconCls:'icon-more'">个人空间</div>
					<div onclick="remove()" data-options="iconCls:'icon-clear'">安全退出</div>
				</div>
			</div>
		</div>
		<div data-options="region:'south',split:true" style="height: 50px;"></div>
		<div data-options="region:'west',split:true" title="导航菜单"
			style="width: 150px;">
			<div id="menuTree">
				<ul id="tt" class="easyui-tree"
					data-options="iconCls:'icon-save',collapsible:true"></ul>
			</div>
			<div id="mm" class="easyui-menu" style="width: 120px;">
				<div onclick="append()" data-options="iconCls:'icon-add'">追加</div>
				<div onclick="remove()" data-options="iconCls:'icon-remove'">移除</div>
			</div>

		</div>
		<div id="centerTabs" data-options="region:'center',iconCls:'icon-ok'"
			style="width: 530px;">
			<div id="tta" class="easyui-tabs"></div>
		</div>
	</div>
	
	 <div id="MessageDialog" class="easyui-dialog" title="我的消息"
		style="width: 260px; height: 260px;"
		data-options="modal:true,closed:true">

		<h3>以下学生被分配给你，请尽快处理！</h3>
		<table id="messages" class="easyui-datagrid">
			<thead>
				<tr>
					<th data-options="field:'mid',title:'ID'"></th>
					<th data-options="field:'sname',title:'学生姓名'"></th>
					<th data-options="field:'times',title:'分配时间'"></th>
				</tr>

			</thead>
		</table>

		<br> &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; <a
			class="easyui-linkbutton" href='javascript:void(0)'
			onclick='RemoveMessage()'>我知道了</a>
	</div>
	<!-- 修改密码 -->
 <div id="updateMMDialog" class="easyui-dialog" title="修改个人密码" style="width:400px;height:200px;"   
        data-options="iconCls:'icon-save',resizable:true,closed:true,modal:false">   
		<form id="updateMMForm" class="easyui-form">
			<table cellpadding="5">
			   <tr>
					<td>原密码:</td>
					<td><input class="easyui-textbox" id="passWord"
						name="passWord" data-options="required:true"></input></td>
				</tr>
				<tr>
					<td>新密码:</td>
					<td><input class="easyui-textbox" id="newPW"
						name="newPW" data-options="required:true"></input></td>
				</tr>
				<tr>
					<td>确认密码:</td>
					<td><input class="easyui-textbox" id="querenPW"
						name="querenPW" data-options="required:true"></input></td>
				</tr>
			</table>
		</form>
		   <div style="text-align: center; padding: 5px">
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitUpdateMM()" data-options="iconCls:'icon-ok'">保存</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeUpdateMM()" data-options="iconCls:'icon-no'">取消</a>
		</div>
	</div>
	 <!-- 通讯录 -->
	<div id="openSend-window" class="easyui-window" title="个人信息"
		style="width: 500px; height: 200px"
		data-options="iconCls:'icon-save',modal:true,closed:true">
		提示语：<select id="msg" class="easyui-combobox" style="width: 120px;">
			<option>----请选择-----</option>
			<option value="您有新增的学生，请注意查看！">您有新增的学生，请注意查看！</option>
			<option value="您有新增的咨询师，请注意查看！">您有新增的咨询师，请注意查看！</option>
			<option value="您有新增的网络咨询，请注意查看！">您有新增的网络咨询，请注意查看！</option>
			<option value="您有未跟踪的学生，请注意跟踪！">您有未跟踪的学生，请注意跟踪！</option>
			<option value="您有未回访的学生，请注意查看！">您有未回访的学生，请注意查看！</option>
			<select> 联系人：
				<select id="UsersAll" class="easyui-combobox" style="width: 120px;">
					<option>----请选择-----</option>
					<select>
						<input type="button" value="发送" onclick="send()" />
	</div>
	
</body>
</html>